﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class MeetingDAO : BaseService
    {
        /// <summary>
        /// 查询即将开始的会议
        /// </summary>
        /// <param name="state"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<Meeting> GetListPagingHistory(int state,int page, int pagesize)
        {
            string hql = "from Meeting where BeginDate >= getdate() order by BeginDate desc";
            return FindList<Meeting>(hql, null, (page - 1) * pagesize, pagesize);
        }

        /// <summary>
        /// 查询历史会议
        /// </summary>
        /// <param name="state"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<Meeting> GetListPagingFuture(int state, int page, int pagesize)
        {
            string hql = "from Meeting where BeginDate < getdate() order by BeginDate desc";
            return FindList<Meeting>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 查询到期会议目数
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        /// 
        public int GetListPagingHistory(int state)
        {
            string hql = "select count(*) from Meeting where BeginDate >=getdate()";
            if (state == -99)
            {
                //hql += " and Id = " + id;
            }
            else
            {
                hql += " and State =" + state;
            }
            return Convert.ToInt32(GetValue(hql));
        }

        /// <summary>
        /// 查询历史会议目录
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public int GetListPagingFuture(int state)
        {
            string hql = "select count(*) from Meeting where BeginDate <getdate()";
            if (state == -99)
            {
                //hql += " and Id = " + id;
            }
            else
            {
                hql += " and State =" + state;
            }
            return Convert.ToInt32(GetValue(hql));
        }




        /// <summary>
        /// 查询当前用户的会议信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="worker"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IList<Meeting> GetListPagingByWorker(int page, int pagesize, string worker, int state)
        {
            string hql = "from Meeting where 1=1";
            if (state == -99)
            {
                hql += " and Worker like '%" + "," + worker + "," + "%'";
            }
            else
            {
                hql += " and Worker like '%" +","+ worker +","+ "%' and State =" + state;
            }
            hql += " order By AddDate Desc";
            return FindList<Meeting>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 根查询当前用户的会议目数
        /// </summary>
        /// <param name="worker"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int GetListPagingByWorker(string worker, int state)
        {
            string hql = "select count(*) from Meeting where 1=1";
            if (state == -99)
            {
                hql += " and Worker like '%" + ","+ worker +","+ "%'";
            }
            else
            {
                hql += " and Worker like '%" +","+ worker +","+ "%' and State =" + state;
            }
            return Convert.ToInt32(GetValue(hql));
        }


        /// <summary>
        /// 查询当前用户未到的会议
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="worker"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IList<Meeting> GetListPagingByWorkerFuture(int page, int pagesize, string worker, int state)
        {
            string hql = "from Meeting where 1=1 and BeginDate > getdate() ";
            if (state == -99)
            {
                hql += " and Worker like '%" + "," + worker + "," + "%'";
            }
            else
            {
                hql += " and Worker like '%" + ","+worker +","+ "%' and State =" + state;
            }
            hql += " order By AddDate Desc";
            return FindList<Meeting>(hql, null, (page - 1) * pagesize, pagesize);
        }
        /// <summary>
        /// 查询当前用户未到的会议数目
        /// </summary>
        /// <param name="worker"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int GetListPagingByWorkerFuture(string worker, int state)
        {
            string hql = "select count(*) from Meeting where 1=1 and BeginDate > getdate()";
            if (state == -99)
            {
                hql += " and Worker like '%" + "," + worker + "," + "%'";
            }
            else
            {
                hql += " and Worker like '%" + ","+ worker  +","+ "%' and State =" + state;
            }
            return Convert.ToInt32(GetValue(hql));
        }



    }
}
